package sort

import "Code/utils"

// SelectSort 选择排序
func SelectSort(arr []int) []int {
	length := len(arr)
	var max, index int

	for i := 0; i < length-1; i++ {
		max = arr[i]
		index = i
		for j := i + 1; j < length; j++ {
			if arr[j] >= max {
				max = arr[j]
				index = j
			}
		}
		if i != index {
			utils.ExchangeIntArr(arr, i, index)
		}

	}

	return arr
}
